﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;

namespace Url
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
		private delegate void MyDelegate();
		private void button1_Click(object sender, EventArgs e)
		{
			textBox1.Text = "https://aoff.whu.edu.cn/info/1004/3821.htm";

			String url = textBox1.Text;
			WebClient webClient = new WebClient();
			byte[] recvdata = webClient.DownloadData(url);       // 指定url下载数据到byte数组中
			string response = Encoding.UTF8.GetString(recvdata); // 获取UTF-8类型编码
			
			//1.读取文件内容到字符串

			//2.创建正则表达式抓取email地址
			MatchCollection matche = Regex.Matches(response, @"[-a-zA-Z0-9_.]+@[-a-zA-Z0-9]+(\.[a-zA-Z0-9]+){1,}");
			MatchCollection matche2 = Regex.Matches(response, @"^[1]+[3,5]+\d{9}");
			foreach (Match item in matche)
			{
				this.BeginInvoke(new MyDelegate(() => { textBox3.Text = item.Value; }));
				
			}
			foreach (Match item in matche2)
			{
				this.BeginInvoke(new MyDelegate(() => { textBox2.Text = item.Value; }));
			}


		}

		private void label1_Click(object sender, EventArgs e)
		{

		}
		
	}
}